//
//  ClientManager.swift
//  MAX-OSS
//
//  Created by 我演示 on 2019/11/8.
//  Copyright © 2019 ALLSall. All rights reserved.
//

import Cocoa

class ClientManager: NSObject {
    var tcpClient : TCPClient
    fileprivate var isClientConnected : Bool = false
    
    init (tcpClient : TCPClient) {
        self.tcpClient = tcpClient
    }
    
}

extension ClientManager {
    func startReadMsg () {
        isClientConnected = true
        while true {
            if let msg =  tcpClient.read(4) {
                let msgData = Data(bytes: msg, count: 4)
                
                var length : Int = 0
                (msgData as NSData).getBytes(&length, length: 4)
                
                //2: 根据长度，读取真实信息
                guard let msg = tcpClient.read(length) else {return}
                
                let data = Data(bytes: msg, count: length)
                let string = String(data: data, encoding: .utf8)
                
                
                
                ///3: 消息类型
             let type = 0
                
                //4: 读取类型
                
            }else {
                isClientConnected = false
                
                
                
                print("连接处理 ")
            }
        }
    }
}
